/*
 * cluster.cpp
 *
 *  Created on: Mar 2, 2011
 *      Author: Mo
 */
//#pragma once
#include "cluster.h"
#include "pixel.h"
#include <stdio.h>

Cluster::Cluster()
{
	this->size = -1;
	this->value = -1;
}

//Cluster::Cluster(Cluster& other)
//{
//	this->size = other.size;
//	this->value = other.value;
//	this->pixels.assign(other.pixels.begin(), other.pixels.end());
//}

Cluster::Cluster(int** data, int s)
{
	this->size = s;
	for (int i = 0; i != s; i++)
		this->pixels.push_back(Pixel(data[i][0], data[i][1], this->value));
}

Cluster::Cluster(int data[][2], int s)
{
	this->size = s;
	for (int i = 0; i != s; i++)
		this->pixels.push_back(Pixel(data[i][0], data[i][1], this->value));
}

Cluster::~Cluster()
{
	this->size = 0;
	this->value = 0;
	this->pixels.resize(0);
}

Cluster& Cluster::operator= (const Cluster& other)
{
	if (&other == this)
		return *this;
	this->size = other.size;
	this->value = other.value;
	this->pixels.assign(other.pixels.begin(), other.pixels.end());
	return *this;
}

void Cluster::clear()
{
	this->pixels.clear();
	this->setSize(0);
}

void Cluster::setSize(int s)
{
	this->size = s;
}

void Cluster::add(Pixel p)
{
	this->pixels.push_back(p);
	this->size++;
}

void Cluster::add(int row, int col)
{
	this->pixels.push_back(Pixel(row, col, this->value));
	this->size++;
}

void Cluster::add(int row, int col, int value)
{
	this->pixels.push_back(Pixel(row, col, value));
	this->size++;
}

Pixel Cluster::element(int index)
{
	return this->pixels[index];
}

int Cluster::getSize()
{
	return this->size;
}

int Cluster::getValue()
{
	return this->value;
}

bool Cluster::includes(Pixel p)
{
	for (int i = 0; i != (int) this->pixels.size(); i++)
		if (this->pixels[i].hasSameCoordinate(p))
			return false;
	return true;
}
